#include "SpriteWindows.h"


Sprite::SpriteWindows::SpriteWindows( HINSTANCE hInstance ):m_HInstance(hInstance)
{
	m_HMainWnd = 0;
	m_nWidth = 800;
	m_nHeight = 600;
	m_strTitle = L"SpriteApp";

	m_bMix = false;

	m_bMax = false;

	m_bFull = false;

	m_bResizing = false;
}

Sprite::SpriteWindows::SpriteWindows( HINSTANCE hInstance,int width,int height,std::wstring title )
	:m_HInstance(hInstance),m_nWidth(width),m_nHeight(height),m_strTitle(title)
{
	m_HMainWnd = 0;

	m_bMix = false;

	m_bMax = false;

	m_bFull = false;

	m_bResizing = false;
}


Sprite::SpriteWindows::~SpriteWindows(void)
{
}

HRESULT Sprite::SpriteWindows::initWindow()
{
	WNDCLASS wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = MainWndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = m_HInstance;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = m_strTitle.c_str();

	if( !RegisterClass(&wc) )
	{
		MessageBox(0, L"RegisterClass FAILED", 0, 0);
		return S_FALSE;
	}

	// Compute window rectangle dimensions based on requested client area dimensions.
	//		RECT R = { 0, 0, m_nHeight, m_nHeight };
	//	AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false);
	//	m_nWidth  = R.right - R.left;
	//	m_nHeight = R.bottom - R.top;

	m_HMainWnd = CreateWindow(m_strTitle.c_str(), m_strTitle.c_str(), 
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, m_nWidth, m_nHeight, 0, 0, m_HInstance, this); 
	if( !m_HMainWnd )
	{
		MessageBox(0, L"CreateWindow FAILED", 0, 0);
		return S_FALSE;
	}
	ShowWindow(m_HMainWnd, SW_SHOW);
	UpdateWindow(m_HMainWnd);
	return S_OK;
}

HWND Sprite::SpriteWindows::getHWND()
{
	return	this->m_HMainWnd;
}

